from devicetest.base.test_suite import TestCase
from devicetest.utils.file_util import get_resource_path
from hypium import UiExplorer, BY
from xdevice import platform_logger

from aw.Common import DeviceUtils, Functions

log = platform_logger("Preload")


# SUB_ACE_UI_COMPONENT_INFOMATION_MARQUEE_ANIMATION_0040
class SUB_ACE_UI_COMPONENT_INFOMATION_MARQUEE_ANIMATION_0040(TestCase):

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        self.tests = ["test_step"]
        TestCase.__init__(self, self.TAG, controllers)
        self.device_operator = DeviceUtils.DeviceUtils(self.device1, self)
        self.driver = UiExplorer(self.device1)

    def setup(self):
        log.info("预置工作:初始化手机开始.................")
        self.sn = self.device1.device_sn
        log.info("SN: {}".format(self.sn))
        # 唤醒
        self.device_operator.wake_up()
        # 解锁设备
        self.device_operator.unlock_deivce()
        # 设置设备常亮
        self.device_operator.keep_screen()
        self.device_operator.send_scrcpy()
        # 设置权限，确保可拉起UiTest
        Functions.run_cmd('hdc -t {} shell setenforce 0'.format(self.sn))
        hap_path = get_resource_path("resource/hap/com.example.animationTest.hap")
        Functions.run_cmd('hdc -t {} install {}'.format(self.sn, hap_path))
        self.driver.start_app("com.example.animationTest")

    def test_step(self):
        self.driver.touch(BY.id('hyperLink'))
        self.driver.wait(1)
        self.driver.touch(BY.id('UIComponentInfomationMarqueeAnimation'))
        self.driver.wait(1)
        self.driver.touch(BY.text('004'))
        self.device_operator.check_animation_compare()
        self.driver.wait(2)

    def teardown(self):
        self.driver.stop_app('com.example.animationTest')
        self.device1.execute_shell_command("rm -f /data/local/tmp/scrcpy-hm")
